package com.xbdnote.java8.study;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.xbdnote.java8.study.service.bo.XbdBo;

/**
 * @Author 小白丁
 * @Date 2021/11/25 21:50
 * @Version 1.0
 * @Description 学习关键字transient使用
 */
public class TransientStudy {

    public static void main(String[] args) {
        XbdBo xbd = new XbdBo();
        xbd.setName("小白丁学习笔记");
        xbd.setUrl("https://blog.csdn.net/qq_37465844");
        xbd.setPassword("123456");
        System.out.println("序列化之前");
        System.out.println(xbd);

        String file = "C:/test/xbd-note.txt";
        try {
            ObjectOutputStream objOutStream = new ObjectOutputStream(
                new FileOutputStream(file));
            objOutStream.writeObject(xbd);
            objOutStream.flush();
            objOutStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            ObjectInputStream objInStream = new ObjectInputStream(new FileInputStream(file));
            XbdBo readXbd = (XbdBo)objInStream.readObject();
            objInStream.close();
            System.out.println("序列化之后");
            System.out.println(readXbd);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
